<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
<script src="${ctx}/static/plugins/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

</head>
<body style="font-family: '微软雅黑'">
<div id="tb" style="padding:5px;height:auto">
        <div>
        	<form id="searchFrom" action="">
       	        <input type="text" name="pname" class="easyui-validatebox" data-options="width:200,prompt: '产品名称'"/>
       	        <input type="text" name="pcode" class="easyui-validatebox" data-options="width:150,prompt: '产品编码'"/>
       	        <input type="text" name="userName" class="easyui-validatebox" data-options="width:150,prompt: '理财师姓名'"/>
       	        <input type="text" name="uid" class="easyui-validatebox" data-options="width:150,prompt: '理财师编码'"/>
       	        <input type="text" name="beginDate" class="easyui-my97" datefmt="yyyy-MM-dd" data-options="width:150,prompt: '预约开始日期'"/>
		        - <input type="text" name="endDate" class="easyui-my97" datefmt="yyyy-MM-dd" data-options="width:150,prompt: '预约结束日期'"/>
       	        <br/>
       	        <input type="text" name="cname" class="easyui-validatebox" data-options="width:150,prompt: '客户姓名'"/>
       	        <input type="text" name="cid" class="easyui-validatebox" data-options="width:150,prompt: '客户编码'"/>
       	        <input type="text" name="orderId" class="easyui-validatebox" data-options="width:200,prompt: '预约编码'"/>
       	        <select name="status" class="easyui-combobox" readonly
						 data-options="width: 150, panelHeight:100">
							<option value="" selected>--全部--</option>
							<option value="0">正在审核</option>
							<option value="1">审核已通过</option>
							<option value="2">审核未通过</option>
				</select>
				
		        <span class="toolbar-item dialog-tool-separator"></span>
		        <a href="javascript(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="cx()">查询</a>
			</form>
			
			<shiro:hasPermission name="lcs:productBill:detail">
	            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-credit-card" plain="true" onclick="viewCard();">查看凭证</a>
	       	<span class="toolbar-item dialog-tool-separator"></span>
	        </shiro:hasPermission>
	       	
	       	<shiro:hasPermission name="lcs:productBill:verify">
	            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-product" plain="true" onclick="examCard();">审核凭证</a>
	        </shiro:hasPermission>
	        
	       	
        </div> 
        
</div>
<table id="dg"></table> 
<div id="dlg"></div> 
<div id="dlg2"></div>  
<script type="text/javascript">
var dg;
$(function(){   
	dg=$('#dg').datagrid({    
	method: "get",
    url:'${ctx}/productBill/json',
    fit : true,
	fitColumns : true,
	border : false,
	striped:true,
	idField : 'id',
	pagination:true,
	rownumbers:true,
	pageNumber:1,
	pageSize : 20,
	pageList : [ 10, 20, 30, 40, 50 ],
	singleSelect:true,
    columns:[[    
		{field:'id',title:'id',hidden:true},  
		{field:'productOrder1',title:'预约编码',sortable:false,align:'center',width:108,formatter:function(value,rowData,rowIndex){
			return rowData.productOrder.id;
		}}, 
		{field:'productOrder2',title:'预约时间',sortable:false,align:'center',width:68,formatter:function(value,rowData,rowIndex){
			return formatTime(rowData.productOrder.orderTime);
		}},
		{field:'productOrder3',title:'产品名称',sortable:false,align:'center',width:100,formatter:function(value,rowData,rowIndex){
			return rowData.productOrder.productInfo.pname;
		}},
		{field:'productOrder4',title:'产品编码',sortable:false,align:'center',width:38,formatter:function(value,rowData,rowIndex){
			return rowData.productOrder.productInfo.pcode;
		}},
		{field:'productOrder5',title:'理财师',sortable:false,align:'center',width:30,formatter:function(value,rowData,rowIndex){
			return rowData.productOrder.user.userName;
		}},
		{field:'productOrder6',title:'理财师编码',sortable:false,align:'center',width:30,formatter:function(value,rowData,rowIndex){
			return rowData.productOrder.user.uid;
		}},
		{field:'productOrder7',title:'客户',sortable:false,align:'center',width:30,formatter:function(value,rowData,rowIndex){
			return rowData.productOrder.cname;
		}},
		{field:'productOrder8',title:'预约金额',sortable:false,align:'center',width:40,formatter:function(value,rowData,rowIndex){
			return formatMoney(rowData.productOrder.investMoney);
		}},
		{field:'createTime',title:'上传凭证时间',sortable:false,align:'center',width:68,formatter:function(value,rowData,rowIndex){
			return formatTime(rowData.createTime);
		}},
        {field:'status',title:'状态',width:32,align:'center',sortable:false,formatter:function(value,rowData,rowIndex){
			if(rowData.status == '2') {
				return "<span style='color: red;'>审核未通过</span>";
			} else if(rowData.status == '1') {
				return "<span style='color: green;'>审核已通过</span>";
			} else {
				return "正在审核";
			} 
		}}
    ]],
    enableHeaderClickMenu: false,
    enableHeaderContextMenu: false,
    enableRowContextMenu: false,
    toolbar:'#tb'
	});
});

//创建查询对象并查询
function cx(){
	var obj=$("#searchFrom").serializeObject();
	obj.pname = encodeURIComponent(obj.pname);
	obj.userName = encodeURIComponent(obj.userName);
	obj.cname = encodeURIComponent(obj.cname);
	dg.datagrid('reload',obj); 
}

//查看凭证
function viewCard() {
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	d=$("#dlg").dialog({   
	    title: '查看上传凭证', 
	    top: 10,
	    width: 500,    
	    height: 620,   
	    href:'${ctx}/productBill/viewCard/'+row.id,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'关闭',
			handler:function(){
					d.panel('close');
				}
		}]
	});
}

//审核凭证
function examCard() {
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	if(row.status != '0') {
		parent.$.messager.alert('该记录已审核！');
		return;
	}
	d=$("#dlg").dialog({   
	    title: '上传凭证审核',
	    top: 10,
	    width: 500,    
	    height: 620,   
	    href:'${ctx}/productBill/viewCard/'+row.id,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'审核通过',
			handler:function(){
				parent.$.messager.confirm('提示', '确认该凭证通过么？', function(data){
					if (data){
						$.ajax({
							type:'get',
							data:{status:'1'},
							url:"${ctx}/productBill/examCard/"+row.id,
							success: function(data){
								d.panel('close');
								dg.datagrid('reload');
							}
						});
					} 
				});
			}
		},{
			text:'审核未通过',
			handler:function(){
				parent.$.messager.confirm('提示', '确认该凭证不通过么？', function(data){
					if (data){
						$.ajax({
							type:'get',
							data:{status:'2'},
							url:"${ctx}/productBill/examCard/"+row.id,
							success: function(data){
								d.panel('close');
								dg.datagrid('reload');
							}
						});
					} 
				});
			}
		},{
			text:'关闭',
			handler:function(){
					d.panel('close');
				}
		}]
	});
}

</script>
</body>
</html>